<template>
  <!-- // 分配角色 -->
  <div>
    <el-checkbox-group v-model="roleIds">
      <el-checkbox v-for="item in roleList" :key="item.id" :label="item.id">{{ item.name }}</el-checkbox>
    </el-checkbox-group>

    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="doSubmit">确定</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </div>
  </div>
</template>
<script>
import { sendRoles, updateRole } from '@/api/settings'
import { getUser } from '@/api/employees'
export default {
  props: {
    curId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      roleList: [],
      // 多选框选中的数据的数组
      roleIds: []
    }
  },
  created() {
    this.getRoles()
    this.getEmployee()
  },
  methods: {
    closeDialog() {

    },
    // 获取多选框所有数据
    async getRoles() {
      const res = await sendRoles({ page: 1, pagesize: 1000 })
      this.roleList = res.data.rows
    },
    // 获取当前员工的权限信息，并渲染给页面
    async getEmployee() {
      const res = await getUser(this.curId)
      this.roleIds = res.data.roleIds
    },
    // 确认添加权限信息
    async doSubmit() {
      await updateRole(this.curId, this.roleIds)
      this.$emit('success')
    }
  }
}
</script>
